package com.zby.business.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.zby.business.R;

import java.net.URL;
import java.util.List;

/**
 * Created by BY on 2015/12/25.
 */
public class ImagePagerAdapter extends PagerAdapter {
    private String[] urls;
    private int[] images;
    private Context context;

    public ImagePagerAdapter(int[] images, Context context, String[] urls) {
        this.images = images;
        this.context = context;
        this.urls=urls;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getCount() {
        if (images.length > 1) {
            return Integer.MAX_VALUE;
        }
        return images.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        int index=position%images.length;
        ImageView imageView = new ImageView(context);
        imageView.setBackgroundResource(images[index]);
        container.addView(imageView);
        return imageView;
    }
}
